using UnityEngine;
using System.Collections;
using System.Collections.Generic;

public class CreateCharacterButton : MonoBehaviour {
	
	public UILabel Name;
	public UILabel Description;
	public UIPopupList gender;
	
	public UIPopupList classes;
	
	public UIPopupList races;
	
	public GameObject CancelButton;
	
	public GameObject WindowPrefab;

	// Use this for initialization
	void Start () {
		UIButtonMessage message = CancelButton.AddComponent<UIButtonMessage>();
		message.target = gameObject;
		message.functionName = "cancelClicked";
		
		List<string> classOptions = new List<string>();
		
		foreach(string cName in ClassManager.index.Keys)
		{
			classOptions.Add(cName);
		}
		
		classes.items = classOptions;
		classes.selection = classes.items[0];
		
		List<string> raceOptions = new List<string>();
		
		foreach(string rName in RaceManager.index.Keys)
		{
			raceOptions.Add(rName);
		}
		
		races.items = raceOptions;
		races.selection = races.items[0];
	}
	
	// Update is called once per frame
	void Update () {
		
	}
	
	void OnClick()
	{
		CharacterSheet character = SheetManager.AddCharacter(Name.text, gender.selection, Description.text);
		character.classes.Add(ClassManager.Load(classes.selection));
		int i = character.classes[0].hpRandomize;
		character.race = RaceManager.Load(races.selection);
		
		SheetManager.activeCharacter = character;
		SheetManager.SaveActiveCharacter();
		
		GameObject g = Instantiate(WindowPrefab) as GameObject;
		g.transform.parent = this.transform.parent.parent;
		g.transform.localScale = Vector3.one;
		
		g.transform.localPosition = Vector3.back*2;
		
		Destroy(transform.parent.gameObject);
	}
	
	void cancelClicked()
	{
		Destroy(transform.parent.gameObject);
	}
}
